<?php

namespace App\Models;


use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Orders extends Model
{

    use SoftDeletes;

    protected $table = 'orders';

    //订单状态：0-待支付预付款，1预约中，2已接单，3正在服务，4未支付，5已支付，6已评价，-1乘客取消，-2司机取消，-3后台取消
    CONST STATUS = [
        '0' => '待支付预约款',
        '1' => '预约中',
        '2' => '已接单',
        '3' => '正在服务',
        '4' => '未支付',
        '5' => '已支付',
        '6' => '已评价',
        '-1' => '乘客取消',
        '-2' => '司机取消',
        '-3' => '后台取消',

    ];

    //代驾类型
    public function getTypesAttribute($types)
    {
        if ($types == 0) return '日常驾';
        if ($types == 1) return '酒后驾';
        if ($types == 2) return '商务驾';
    }

    /**
     * 公司
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     * @Author 姿势就是力量
     */
    public function corporation()
    {
        return $this->belongsTo(Company::class, 'company_id', 'id');
    }


    /**
     * 司机
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     * @Author 姿势就是力量
     */
    public function driver()
    {
        return $this->belongsTo(Drivers::class, 'driver_id', 'id');
    }


    /**
     * 乘客
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     * @Author 姿势就是力量
     */
    public function passenger()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }


    /**
     * 业务类型
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     * @Author 姿势就是力量
     */
    public function serviceType()
    {
        return $this->belongsTo(ServiceType::class, 'service_type_id', 'id');
    }


    /**
     * 评论
     * @Author 姿势就是力量
     */
    public function comment()
    {
        return $this->hasOne(Comment::class, 'order_id', 'id');
    }


    /**
     * 车辆信息
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     * @Author 姿势就是力量
     */
    public function car()
    {
        return $this->belongsTo(Car::class, 'car_id', 'id');
    }


    /**
     * 订单路程
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     * @Author 姿势就是力量
     */
    function service()
    {
        return $this->hasOne(Service::class, 'id', 'service_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     * 关联订单表
     */
    function order_distance()
    {
        return $this->hasOne(OrderDistance::class, 'order_id', 'id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function distance()
    {
        return $this->hasOne(OrderDistance::class, 'order_id', 'id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function user()
    {
        return $this->hasOne(User::class, 'id', 'user_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    function pay_order()
    {
        return $this->hasOne(PayOrder::class, 'order_id', 'id');
    }
}
